package com.quanshu.change.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

import com.quanshu.change.tool.BaseTool;


/**
 * 作者  李哲
 * 创建时间 2018/10/23
 * 邮箱 lizhetongliao@163.com
 * 说明
 **/
@SuppressLint("AppCompatCustomView")
public class CustomImgview extends ImageView {
    Context context;
    public CustomImgview(Context context) {
        super(context);
        this.context=context;
    }

    public CustomImgview(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Drawable drawable = getDrawable();
        if (drawable != null) {
//            int width = MeasureSpec.getSize(widthMeasureSpec);
            Log.d("tool", "onMeasure: "+drawable);
            int width = BaseTool.getAndroiodScreenLand(context);
            int height = (int) Math.ceil((float) width * (float) drawable.getIntrinsicHeight() / (float) drawable.getIntrinsicWidth());
            //int height =  BaseTool.getAndroiodScreenProperty(context)+(int) ((float)48/BaseTool.getAndroiodDp(context));
            setMeasuredDimension(width, height);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}
